<!-- PagerList 试卷列表 -->
<template>
  <div class="content">
    <div class="content-container">
      <div class="content-btn">
        <Cbutton @click="handleAdd">添加试卷</Cbutton>
      </div>
      <el-table :data="tableList" v-loading="tableLoading" ref="tableData" border fit>
        <el-table-column label="序号" type="index" align="center" width="70"></el-table-column>
        <el-table-column label="试卷名称" prop="title" align="center" min-width="200"></el-table-column>
        <el-table-column label="试卷类型" prop="type" align="center" min-width="80">
          <template slot-scope="scope">
            {{dealStr(scope.row.type, 'paperTypeList')}}
          </template>
        </el-table-column>
        <el-table-column label="题数" prop="topicCount" align="center" min-width="80"></el-table-column>
        <el-table-column label="总分值" prop="maxScore" align="center" min-width="80"></el-table-column>
        <!-- <el-table-column label="已关联培训" prop="" align="center" min-width="200"></el-table-column> -->
        <el-table-column prop="createTime" label="创建时间" align="center" min-width="160">
          <template slot-scope="scope">
            {{scope.row.createTime | glbTimeFormat}}
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center" fixed="right" min-width="100">
          <template slot-scope="prop">
            <el-button type="text" size="medium" @click="handleUpdate(prop.row)">编辑</el-button>
            <el-button type="text" size="medium" style="color: #F56C6C;" @click="handleRemove(prop.row)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>

      <Pagination @pageChange="getPage" :pageDefultData="{
        pageNum: query.pageNum,
        pageRow: query.pageSize,
        totalCount: totalCount }">
      </Pagination>
    </div>
  </div>
</template>

<script>
import { ExportStr } from '@/utils'
import { GetPaperList, RemovePaper } from '@/api/train'
export default {
  name: 'PagerList',
  components: {},
  data () {
    return {
      query: {
        pageNum: 1,
        pageSize: 10
      },
      totalCount: 0,
      tableList: [],
      tableLoading: false
    }
  },
  props: {},
  watch: {},
  computed: {},
  mounted () {
    this.getList()
  },
  methods: {
    handleAdd () {
      this.$router.push({ name: 'train:paper:add' })
    },
    handleUpdate (row) {
      this.$router.push({ name: 'train:paper:edit', query: { id: row.id } })
    },
    handleRemove (row) {
      this.$confirm(`确定要删除该试卷吗？`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        let parmas = { id: row.id, isDelete: 1 }
        RemovePaper(parmas).then(res => {
          this.$message.success(res.message || '删除成功')
          this.getList()
        }).catch(() => { })
      }).catch(() => { })
    },
    getList () {
      let params = JSON.parse(JSON.stringify(this.query))
      this.tableLoading = true
      GetPaperList(params).then(res => {
        this.tableLoading = false
        const data = res.data
        this.tableList = data.list
        this.totalCount = data.total
      }).catch(e => {
        this.tableLoading = false
      })
    },
    getPage (val) {
      this.query.pageNum = val.pageNum
      this.query.pageSize = val.pageRow
      this.getList()
    },
    dealStr (key, arrayKey) {
      return ExportStr(key, arrayKey)
    }
  }
}

</script>
<style lang='scss' scoped>
</style>
